package com.houtai.service.leading.figure;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.houtai.base.Page;
import com.houtai.bean.dto.leading.figure.TdLeadingFigureDetailDto;
import com.houtai.bean.vo.leading.figure.TdLeadingFigureDetail;
import com.houtai.bean.vo.leading.figure.TdLeadingFigureDetailVo;
import com.houtai.bean.vo.leading.figure.TdLeadingFigureList;
import com.houtai.bean.vo.leading.figure.TdLeadingFigureListVo;
import com.houtai.dao.TdLeadingFigureDao;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class LeadingFigureService {
    private static Logger logger = Logger.getLogger(LeadingFigureService.class);
    @Autowired
    private TdLeadingFigureDao tdLeadingFigureDao;


    /**
     * @Purpose:    领军人物列表
     * @param:      dto
     * @Version:    1.0
     * @Author:     li
     * @time:       2019/8/21
     * @return:     TdLeadingFigureListVo
     */
    public TdLeadingFigureListVo leadingFigureList(Page dto) {
        String logInfo = this.getClass().getName() + ":leadingFigureList:";
        TdLeadingFigureListVo retInfo = new TdLeadingFigureListVo();
        logger.info("======" + logInfo + "begin======");
        try {
            String orderBy = "sort DESC,lf_id desc";

            PageHelper.startPage(dto.getCurrent_page(), dto.getPage_size(), orderBy);
            List<TdLeadingFigureList> lists = tdLeadingFigureDao.findTdLeadingFigureList();
            PageInfo<TdLeadingFigureList> list = new PageInfo<>(lists);
            if (list.getTotal() > 0) {

                retInfo.setCurrent_page(dto.getCurrent_page());
                retInfo.setList(list.getList());
                retInfo.setPage_size(list.getPageSize());
                retInfo.setTotal_record(list.getTotal());
                retInfo.setPages(list.getPages());
                retInfo.setMark("0");
                retInfo.setTip("查询成功");
            } else {
                retInfo.setMark("1");
                retInfo.setTip("无领军人物");
            }

        } catch (Exception e) {
            logger.error("======error:" + e.toString() + "======");
            retInfo.setMark("-1");
            retInfo.setTip("系统错误");
        }
        logger.info("======" + logInfo + "end======");
        return retInfo;
    }
    /**
     * @Purpose:    领军人物详情
     * @param:      dto
     * @Version:    1.0
     * @Author:     li
     * @time:       2019/8/21
     * @return:     ResultVo
     */
    public synchronized TdLeadingFigureDetailVo detail(TdLeadingFigureDetailDto dto) {
        String logInfo = this.getClass().getName() + ":detail:";
        TdLeadingFigureDetailVo retInfo = new TdLeadingFigureDetailVo();
        logger.info("======" + logInfo + "begin======");
        try {
            TdLeadingFigureDetail detail = tdLeadingFigureDao.findTdLeadingFigureDetail(dto.getLf_id());
            if (detail != null) {
                retInfo.setDetail(detail);
                retInfo.setMark("0");
                retInfo.setTip("成功");
            } else {
                retInfo.setMark("1");
                retInfo.setTip("领军人物不存在");
            }

        } catch (Exception e) {
            logger.error("======error:" + e.toString() + "======");
            retInfo.setMark("-1");
            retInfo.setTip("系统错误");
        }
        logger.info("======" + logInfo + "end======");
        return retInfo;
    }
}
